package com.a0soft.gphone.aTruffleHog.wnd.stat;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.app.Fragment;

import com.a0soft.gphone.aTruffleHog.R;
import com.a0soft.gphone.aTruffleHog.pref.Pref;

public class OsStatsPager extends BaseViewPager {
    private String[] m_strTitles;
    private String[] m_strMIDs;
    
    ////////////////////////////////////////
    @Override protected int
    GetViewPagerID()
    {
        return VIEW_PAGER_OS_ID;
    }
    
    @Override protected String[] 
    GetTitles(Context ctx)
    {
        if (m_strTitles == null) {
            ArrayList<String> strOtherDevices = Pref.GetOtherDevices(ctx);
            final int N = 2 + strOtherDevices.size() / 2;
            
            m_strTitles = new String[N];
            m_strMIDs = new String[N];
            
            m_strTitles[0] = ctx.getString(R.string.stats_my_device);
            m_strTitles[1] = ctx.getString(R.string.stats_all_devices);
            for (int i = 2; i < N; i++) {
                m_strMIDs[i] = strOtherDevices.get((i - 2) * 2);
                m_strTitles[i] = strOtherDevices.get((i - 2) * 2 + 1);
            }
        }
        return m_strTitles;
    }

    @Override protected Fragment 
    GetPage(Context ctx, int nPos)
    {
        if (nPos == 0)
            return OsStatsFrg.NewInstance(ctx, OsStatsFrg.TYPE_MY_DEVICE, null);
        else if (nPos == 1)
            return OsStatsFrg.NewInstance(ctx, OsStatsFrg.TYPE_ALL_DEVICES, null);
        else
            return OsStatsFrg.NewInstance(ctx, OsStatsFrg.TYPE_USER_DEFINED, m_strMIDs[nPos]);
    }
}
